<?php
class NewsController extends DefaultModuleController {

	public function actionView() {
		$id = getgpc(2);
		
		$newsView = $this->ArticleModel->find("articleId='$id' ",1,1000, 'id DESC');
		
		
		$newsDate = $this->ArticleModel->updateByPk($id,array(
			'views'=>'+1'
		));
		
		$title = $newsView['title'];
		$content = $newsView['content'];
		$author = $newsView['author'];
		$source = $newsView['source'];
		$createdTime2 = date('Y-m-d', $newsView['createdTime']);
		
		$this->header['title'] = $title.$this->header['title'];
		$this->view->assign('title',$title);
		$this->view->assign('author',$author);
		$this->view->assign('source',$source);
		$this->view->assign('content',$content);
		$this->view->assign('createdTime2',$createdTime2);
		$this->view->assign('newsList',$newsView);
		$this->display('news_view');
	}
	
	public function actionList(){
		$page = intval(getgpc('page'));
		if (!$page) $page = 1;
		$search = getgpc('search');
		$id = getgpc(2);
		if ($search) {
			$sqladd = "title like '%".$search."%' " ;
		}
		else {
			$sqladd = "categoryId='$id' ";
		}
		$newsList = $this->ArticleModel->findAll($sqladd, $page, GODHOUSE_PPP3, 'articleId DESC');
		foreach ($newsList as &$v){
			$v['createdTime2'] = date("Y-m-d",$v['createdTime']);
		}
		
		
		$num = $this->ArticleModel->count($sqladd);
		$multipage = $this->page($num, GODHOUSE_PPP3, $page, 'news-list-'.$id.'.htm');
		
		$this->view->assign('id',$id);
		$this->view->assign('multipage', $multipage);
		$this->view->assign('newsList',$newsList);

		$this->display('news_list');
	}
}